package com.zhongjian.technologycal.mall.activity.shoppingcart.activity;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.zhongjian.technologycal.mall.R;
import com.zhongjian.technologycal.mall.activity.main.activity.PayOrderItemsActivity;
import com.zhongjian.technologycal.mall.activity.main.activity.PaymentOrderActivity;
import com.zhongjian.technologycal.mall.activity.main.bean.OrderHeads;
import com.zhongjian.technologycal.mall.activity.main.bean.OrderLines;
import com.zhongjian.technologycal.mall.activity.main.bean.OrderModelBean;
import com.zhongjian.technologycal.mall.activity.personal.SettingsActivity;
import com.zhongjian.technologycal.mall.activity.personal.activity.NewsAddressListActivity;
import com.zhongjian.technologycal.mall.activity.personal.activity.PayOrderActivity;
import com.zhongjian.technologycal.mall.activity.shoppingcart.bean.ProductListBean;
import com.zhongjian.technologycal.mall.adapter.ConfrmOedersAdapter;
import com.zhongjian.technologycal.mall.base.BaseActivity;
import com.zhongjian.technologycal.mall.bean.AddressComBean;
import com.zhongjian.technologycal.mall.bean.BaseBean;
import com.zhongjian.technologycal.mall.bean.PayBean;
import com.zhongjian.technologycal.mall.bean.UserInfoBean;
import com.zhongjian.technologycal.mall.net.HttpRetrofitClient;
import com.zhongjian.technologycal.mall.utils.AppTools;
import com.zhongjian.technologycal.mall.utils.LoadingDialog;
import com.zhongjian.technologycal.mall.utils.LogUtils;
import com.zhongjian.technologycal.mall.utils.NetWorkUtils;
import com.zhongjian.technologycal.mall.utils.StatusBarUtil;
import com.zhongjian.technologycal.mall.utils.ToastUitl;
import com.zhongjian.technologycal.mall.utils.UserUtils;
import com.zhongjian.technologycal.mall.view.ListViewForScrollView;
import com.zhongjian.technologycal.mall.view.PasswordInputView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import butterknife.BindView;
import butterknife.OnClick;
import me.drakeet.materialdialog.MaterialDialog;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import rx.Subscriber;

/**
 * Created by wei on 2018/3/7.
 * 购物车订单结算
 */

public class ConfirmNewCartOrderActivity extends BaseActivity {
    @BindView(R.id.tv_main_title)
    TextView tv_main_title;
    @BindView(R.id.confirm_lv_goods)
    ListViewForScrollView confirm_lv_goods;
    @BindView(R.id.confirm_address_tv_name)
    TextView confirm_address_tv_name;
    @BindView(R.id.confirm_address_tv_phone)
    TextView confirm_address_tv_phone;
    @BindView(R.id.confirm_address_tv_details)
    TextView confirm_address_tv_details;

    @BindView(R.id.confirm_use_tv_Coupon)
    TextView confirm_use_tv_Coupon;
    @BindView(R.id.confirm_use_tv_RemainPoints)
    TextView confirm_use_tv_RemainPoints;
    @BindView(R.id.confirm_use_tv_RemainElecNum)
    TextView confirm_use_tv_RemainElecNum;

    @BindView(R.id.confirm_tv_tatol_money)
    TextView confirm_tv_tatol_money;
    @BindView(R.id.confirm_shopping_tv_total_price)
    TextView confirm_shopping_tv_total_price;

    @BindView(R.id.confirm_deduction_tv_Coupon)
    TextView confirm_deduction_tv_Coupon;
    @BindView(R.id.confirm_deduction_tv_RemainPoints)
    TextView confirm_deduction_tv_RemainPoints;
    @BindView(R.id.confirm_deduction_tv_RemainElecNum)
    TextView confirm_deduction_tv_RemainElecNum;

    @BindView(R.id.confirm_ll_add_address)
    LinearLayout confirm_ll_add_address;
    @BindView(R.id.confirm_shopping_et_content)
    EditText confirm_shopping_et_content;
    List<List<ProductListBean>> listBeans0 = new ArrayList<>();
    List<ProductListBean> listBeans = new ArrayList<>();
    Map<List<ProductListBean>, Map<String, Double>> everyList = new HashMap<>();

    private ConfrmOedersAdapter confrmOedersAdapter;
    private int addressId;
    private double coupon1 = 0;//现金红包
    private double remainPoints1 = 0;//购物币
    private double remainElecNum1 = 0;//现金币
    private int REQUESTCODE = 10001;
    private double realPrice = 0;
    private String shopName;
    private Dialog payDialog = null;
    private String orderNoC;
    private Dialog hintDialog = null;
    private boolean isNoAddress = false;
    private MaterialDialog materialDialog = null;

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.activity_confirm_cart_order;
    }

    @Override
    protected void beforeInit() {
        super.beforeInit();
//        StatusBarUtil.setColorNoTranslucent(this, getResources().getColor(R.color.border_color));
//        StatusBarUtil.setMiuiStatusBarDarkMode(this, true);

    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        tv_main_title.setText("订单结算");
        listBeans0 = (List<List<ProductListBean>>) getIntent().getSerializableExtra("goodsInfo");
        for (int i = 0; i < listBeans0.size(); i++) {
            for (int j = 0; j < listBeans0.get(i).size(); j++) {
                listBeans.add(listBeans0.get(i).get(j));
            }
        }
        initViewPersonInfo();
        shopName = getIntent().getStringExtra("shopName");
        confrmOedersAdapter = new ConfrmOedersAdapter(getBaseContext(), listBeans);
        confirm_lv_goods.setAdapter(confrmOedersAdapter);

    }

    /**
     * 结算订单1
     *
     * @param forList
     */
    private Map<String, Double> initRealpay(List<ProductListBean> forList) {
        java.text.DecimalFormat df = new java.text.DecimalFormat("#0.00");
        double totalMoney = 0;
        double coupon = 0;//现金红包
        double coupon2 = 0;//现金红包
        double remainPoints2 = 0; //购物币
        double remainElecNum2 = 0;//现金币
        for (int i = 0; i < forList.size(); i++) {
            double price = forList.get(i).getProductSpec().getPrice() ;
            double elecNum = forList.get(i).getProductSpec().getElecNum() / 2;
            int productNum = forList.get(i).getProductnum();
            double integral = price * productNum;
            double integral1 = elecNum * productNum;
            totalMoney += integral;
            coupon += integral1;
        }
        if (coupon1 >= coupon) {
            coupon2 = coupon;
            realPrice = AppTools.sub(totalMoney,coupon2);
        } else {
            coupon2 = coupon1;
            realPrice = AppTools.sub(totalMoney,coupon2);
        }

        if (remainPoints1 >= realPrice) {
            remainPoints2 = realPrice;
            realPrice = 0;
        } else {
            remainPoints2 = remainPoints1;
            realPrice = AppTools.sub(realPrice,remainPoints2);
        }
        if (remainElecNum1 >= realPrice) {
            remainElecNum2 = realPrice;
            realPrice = 0;
        } else {
            remainElecNum2 = remainElecNum1;
            realPrice = AppTools.sub(realPrice,remainElecNum2);
        }
        confirm_tv_tatol_money.setText("¥ " + df.format(totalMoney));
        confirm_deduction_tv_Coupon.setText("- ¥" + df.format(coupon2));
        confirm_deduction_tv_RemainPoints.setText("- ¥" + df.format(remainPoints2));
        confirm_deduction_tv_RemainElecNum.setText("- ¥" + df.format(remainElecNum2));
        confirm_shopping_tv_total_price.setText("¥" + df.format(realPrice));
        Map<String, Double> realMap = new HashMap<>();
        realMap.put("totalMoney", totalMoney);
        realMap.put("coupon2", coupon2);
        realMap.put("remainPoints2", remainPoints2);
        realMap.put("remainElecNum2", remainElecNum2);
        realMap.put("realPrice", realPrice);
        return realMap;
    }

    /**
     * 结算订单2
     *
     * @param forList
     * @return
     */
    private Map<String, Double> initRealpay1(List<ProductListBean> forList) {
        java.text.DecimalFormat df = new java.text.DecimalFormat("#0.00");
        double totalMoney = 0;
        double coupon = 0;//现金红包
        double coupon2 = 0;//现金红包
        double remainPoints2 = 0; //购物币
        double remainElecNum2 = 0;//现金币
        for (int i = 0; i < forList.size(); i++) {
            double price = forList.get(i).getProductSpec().getPrice();
            double elecNum = forList.get(i).getProductSpec().getElecNum() / 2;
            int productNum = forList.get(i).getProductnum();
            double integral = price * productNum;
            double integral1 = elecNum * productNum;
            totalMoney += integral;
            coupon += integral1;
        }
        if (coupon1 >= coupon) {
            coupon2 = coupon;
            coupon1 = AppTools.sub(coupon1,coupon2);
            realPrice = AppTools.sub(totalMoney,coupon2);
        } else {
            coupon2 = coupon1;
            coupon1 = 0;
            realPrice = AppTools.sub(totalMoney,coupon2);
        }

        if (remainPoints1 >= realPrice) {
            remainPoints1 = AppTools.sub(remainPoints1,realPrice);
            remainPoints2 = realPrice;
            realPrice = 0;
        } else {
            remainPoints2 = remainPoints1;
            remainPoints1 = 0;
            realPrice = AppTools.sub(realPrice,remainPoints2);
        }
        if (remainElecNum1 >= realPrice) {
            remainElecNum1 = AppTools.sub(remainElecNum1,realPrice);
            remainElecNum2 = realPrice;
            realPrice = 0;
        } else {
            remainElecNum2 = remainElecNum1;
            remainElecNum1 = 0;
            realPrice = AppTools.sub(realPrice,remainElecNum2);
        }
        confirm_tv_tatol_money.setText("¥ " + df.format(totalMoney));
        confirm_deduction_tv_Coupon.setText("- ¥" + df.format(coupon2));
        confirm_deduction_tv_RemainPoints.setText("- ¥" + df.format(remainPoints2 ));
        confirm_deduction_tv_RemainElecNum.setText("- ¥" + df.format(remainElecNum2 ));
        confirm_shopping_tv_total_price.setText("¥" + df.format(realPrice ));
        Map<String, Double> realMap = new HashMap<>();
        realMap.put("totalMoney", totalMoney);
        realMap.put("coupon2", coupon2);
        realMap.put("remainPoints2", remainPoints2);
        realMap.put("remainElecNum2", remainElecNum2);
        realMap.put("realPrice", realPrice);
        return realMap;
    }

    /**
     * 默认地址获取
     */
    @Override
    public void initPresenter() {
        if (!NetWorkUtils.isNetConnected(getBaseContext())) {
            ToastUitl.showShort(R.string.no_net);
            return;
        } else {
            HttpRetrofitClient.getInstance(getBaseContext()).postUrlRequest(UserUtils.getUserToken(),
                    new Subscriber<ResponseBody>() {
                        @Override
                        public void onStart() {
                            super.onStart();
                            LoadingDialog.showDialogForLoading(ConfirmNewCartOrderActivity.this);
                        }

                        @Override
                        public void onCompleted() {
                            LoadingDialog.cancelDialogForLoading();
                        }

                        @Override
                        public void onError(Throwable e) {
                            LogUtils.logd("error", e.getMessage());
                        }

                        @Override
                        public void onNext(ResponseBody responseBody) {
                            LoadingDialog.cancelDialogForLoading();
                            try {
                                Gson gson = new Gson();
                                AddressComBean userAddressBean = gson.fromJson(responseBody.string(), AddressComBean.class);
                                if (userAddressBean.getError_code() == 0) {
                                    isNoAddress = true;
                                    confirm_address_tv_name.setText(userAddressBean.getData().getName());
                                    confirm_address_tv_phone.setText(userAddressBean.getData().getPhone());
                                    confirm_address_tv_details.setText(
                                            userAddressBean.getData().getProvinceName()
                                                    + userAddressBean.getData().getCityName()
                                                    + userAddressBean.getData().getRegionName()
                                                    + userAddressBean.getData().getDetailAddress());
                                    addressId = userAddressBean.getData().getId();

                                } else if (userAddressBean.getError_code() == 3) {
                                    Intent intent = new Intent();
                                    intent.setAction("com.broadcast.info_out_line");
                                    sendBroadcast(intent);

                                } else if (userAddressBean.getError_code() == -1) {
                                    isNoAddress = false;
                                } else {
                                    ToastUitl.showShort(userAddressBean.getError_message());
                                }

                            } catch (Exception e) {
                                e.printStackTrace();
                            }


                        }
                    });
        }

    }

    /**
     * 获取钱包数据
     */
    private void initViewPersonInfo() {
        if (!NetWorkUtils.isNetConnected(getBaseContext())) {
            ToastUitl.showShort(R.string.no_net);
            return;
        } else {
            HttpRetrofitClient.getInstance(getBaseContext()).getUrlRequestAccountBalance(UserUtils.getUserToken(),
                    new Subscriber<ResponseBody>() {
                        @Override
                        public void onNext(ResponseBody responseBody) {
                            try {
                                Gson gson = new Gson();
                                UserInfoBean userInfoBean = gson.fromJson(responseBody.string(), UserInfoBean.class);
                                if (userInfoBean.getError_code() == 0) {
                                    coupon1 = userInfoBean.getData().getPersonDataMap().getCoupon();
                                    remainElecNum1 = userInfoBean.getData().getPersonDataMap().getRemainElecNum();
                                    remainPoints1 = userInfoBean.getData().getPersonDataMap().getRemainPoints();
                                    confirm_use_tv_Coupon.setText("可用现金红包 " + coupon1);
                                    confirm_use_tv_RemainElecNum.setText("可用现金币 " + remainElecNum1);
                                    confirm_use_tv_RemainPoints.setText("可用购物币 " + remainPoints1);
                                } else if (userInfoBean.getError_code() == 3) {
                                    Intent intent = new Intent();
                                    intent.setAction("com.broadcast.info_out_line");
                                    sendBroadcast(intent);
                                } else {
                                    ToastUitl.showShort(userInfoBean.getError_message());
                                }


                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }

                        @Override
                        public void onCompleted() {
                            initRealpay(listBeans);
                        }

                        @Override
                        public void onError(Throwable e) {
                            ToastUitl.showShort(e.getMessage());

                        }


                    });

        }
    }

    /**
     * 验证支付密码
     *
     * @param password
     */

    private void initRequestPayPassword(String password) {
        HttpRetrofitClient.getInstance(getBaseContext())
                .postUrlRequestPayPassword(UserUtils.getUserToken(),
                        password, new Subscriber<ResponseBody>() {
                            @Override
                            public void onStart() {
                                super.onStart();
                            }

                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {

                            }

                            @Override
                            public void onNext(ResponseBody responseBody) {
                                try {
                                    Gson gson = new Gson();
                                    BaseBean baseBean = gson.fromJson(responseBody.string(), BaseBean.class);
                                    if (baseBean.getError_code() == 0) {
                                        ToastUitl.showShort(baseBean.getError_message());
                                        initRequestPayOrderNoC(orderNoC);
                                    } else if (baseBean.getError_code() == 3) {
                                        Intent intent = new Intent();
                                        intent.setAction("com.broadcast.info_out_line");
                                        sendBroadcast(intent);
                                    } else {
                                        ToastUitl.showShort(baseBean.getError_message());
                                    }

                                } catch (Exception e) {
                                    e.printStackTrace();
                                }

                            }
                        });

    }

    /**
     * 同步处理支付父订单
     *
     * @param
     */

    private void initRequestPayOrderNoC(String orderNoC) {
        HttpRetrofitClient.getInstance(getBaseContext())
                .postUrlRequestgetPayOrderC(UserUtils.getUserToken(),
                        orderNoC, new Subscriber<ResponseBody>() {
                            @Override
                            public void onStart() {
                                super.onStart();
                            }

                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {

                            }

                            @Override
                            public void onNext(ResponseBody responseBody) {
                                try {
                                    Gson gson = new Gson();
                                    BaseBean baseBean = gson.fromJson(responseBody.string(), BaseBean.class);
                                    if (baseBean.getError_code() == 0) {
                                        ToastUitl.showShort(baseBean.getError_message());
                                        finish();
                                    } else if (baseBean.getError_code() == 3) {
                                        Intent intent = new Intent();
                                        intent.setAction("com.broadcast.info_out_line");
                                        sendBroadcast(intent);
                                    } else {
                                        ToastUitl.showShort(baseBean.getError_message());
                                    }

                                } catch (Exception e) {
                                    e.printStackTrace();
                                }

                            }
                        });

    }

    /**
     * 订单提交
     */
    private void initViewRequestCommit() {
        if (!NetWorkUtils.isNetConnected(getBaseContext())) {
            ToastUitl.showShort(R.string.no_net);
            return;
        } else {
            for (int i = 0; i < listBeans0.size(); i++) {
                Map<String, Double> everyMap = initRealpay1(listBeans0.get(i));
                everyList.put(listBeans0.get(i), everyMap);
            }
            OrderModelBean orderModelBean = new OrderModelBean();
            orderModelBean.setAdrressId(addressId);
            List<OrderHeads> listPersons = new ArrayList<>();
            Iterator<Map.Entry<List<ProductListBean>, Map<String, Double>>> it = everyList.entrySet().iterator();
            while (it.hasNext()) {
                List<OrderLines> listSchoolInfo1 = new ArrayList<>();
                Map.Entry<List<ProductListBean>, Map<String, Double>> entry = it.next();
                OrderHeads orderHeads = new OrderHeads();
                orderHeads.setMemo(confirm_shopping_et_content.getText().toString().trim());
                Log.v("--gg--",""+ entry.getKey().size());
                orderHeads.setProducername(entry.getKey().get(0).getProduct().getProducername());
                orderHeads.setRealPay(entry.getValue().get("realPrice"));
                orderHeads.setUseElecNum(entry.getValue().get("remainElecNum2"));
                orderHeads.setUseCoupon(entry.getValue().get("coupon2"));
                orderHeads.setFreight(0);
                orderHeads.setProducerno(entry.getKey().get(0).getProduct().getProducerno());
                orderHeads.setProducertel(entry.getKey().get(0).getProduct().getProducertel());
                orderHeads.setUseVIPRemainNum(0);
                orderHeads.setUsePointNum(entry.getValue().get("remainPoints2"));
                orderHeads.setTotalAmount(entry.getValue().get("totalMoney"));
                for (int j = 0; j < entry.getKey().size(); j++) {
                    OrderLines orderLines = new OrderLines();
                    orderLines.setProductNum(entry.getKey().get(j).getProductnum());
                    orderLines.setProductId(entry.getKey().get(j).getProduct().getId());
                    orderLines.setSpecId(entry.getKey().get(j).getProductSpec().getId());
                    listSchoolInfo1.add(orderLines);
                }
                orderHeads.setOrderLines(listSchoolInfo1);
                listPersons.add(orderHeads);
            }
            orderModelBean.setOrderHeads(listPersons);
            Gson gson = new Gson();
            RequestBody body = RequestBody.create(
                    okhttp3.MediaType.parse("application/json; charset=utf-8"), gson.toJson(orderModelBean));

            HttpRetrofitClient.getInstance(getBaseContext())
                    .getUrlRequestCommit(
                            UserUtils.getUserToken(), body,
                            new Subscriber<ResponseBody>() {
                                @Override
                                public void onStart() {
                                    super.onStart();
                                    LoadingDialog.showDialogForLoading(ConfirmNewCartOrderActivity.this);
                                }

                                @Override
                                public void onCompleted() {
                                    LoadingDialog.cancelDialogForLoading();

                                }

                                @Override
                                public void onError(Throwable e) {
                                    LoadingDialog.cancelDialogForLoading();
                                }

                                @Override
                                public void onNext(ResponseBody responseBody) {
                                    LoadingDialog.cancelDialogForLoading();
                                    try {
                                        Gson gson = new Gson();
                                        PayBean payBean = gson.fromJson(responseBody.string(), PayBean.class);
                                        /**
                                         * type = 1 本地扣除钱
                                         * type = 2 跳支付宝
                                         * type = 3 跳支付宝
                                         */
                                        if (payBean.getError_code() == 0) {
                                            if (payBean.getData().getType().equals("1")) {
                                                orderNoC = payBean.getData().getOrderNoC();
                                                payDialog = new Dialog(ConfirmNewCartOrderActivity.this, R.style.dialog_style1);
                                                LinearLayout layout;
                                                LayoutInflater inflater = (LayoutInflater) ConfirmNewCartOrderActivity.this
                                                        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                                                layout = (LinearLayout) inflater.inflate(R.layout.dialog_hint,
                                                        null);
                                                final PasswordInputView tv_hint = (PasswordInputView) layout
                                                        .findViewById(R.id.again_paypswd_pet);
                                                layout.findViewById(R.id.dialog_btn_cancel).setOnClickListener(
                                                        new View.OnClickListener() {

                                                            @Override
                                                            public void onClick(View v) {
                                                                payDialog.dismiss();
                                                            }
                                                        });
                                                layout.findViewById(R.id.dialog_btn_ensure).setOnClickListener(
                                                        new View.OnClickListener() {
                                                            @Override
                                                            public void onClick(View view) {
                                                                if (TextUtils.isEmpty(tv_hint.getText().toString().trim())) {
                                                                    ToastUitl.showShort("支付密码不能为空");
                                                                    return;
                                                                } else if (tv_hint.getText().toString().trim().length() < 6) {
                                                                    ToastUitl.showShort("请输入6位的支付密码");
                                                                    return;
                                                                }
                                                                initRequestPayPassword(tv_hint.getText().toString().trim());
                                                                payDialog.dismiss();
                                                            }
                                                        });
                                                payDialog.setContentView(layout);
                                                payDialog.show();

                                            } else if (payBean.getData().getType().equals("2")) {
                                                Intent intent = new Intent();
                                                intent.setClass(getBaseContext(), PayOrderItemsActivity.class);
                                                intent.putExtra("singData", payBean.getData().getSingData());
                                                startActivity(intent);
                                                finish();
                                            } else if (payBean.getData().getType().equals("3")) {
                                                Intent intent = new Intent();
                                                intent.setClass(getBaseContext(), PayOrderItemsActivity.class);
                                                intent.putExtra("singData", payBean.getData().getSingData());
                                                startActivity(intent);
                                                finish();
                                            } else {
                                                ToastUitl.showShort(payBean.getError_message());
                                            }

                                        } else if (payBean.getError_code() == 3) {
                                            Intent intent = new Intent();
                                            intent.setAction("com.broadcast.info_out_line");
                                            sendBroadcast(intent);
                                        } else {
                                            ToastUitl.showShort(payBean.getError_message());

                                        }


                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }

                                }
                            });

        }

    }

    @OnClick(R.id.iv_back_page)
    public void onClickBack() {
        finish();
    }

    @OnClick(R.id.confirm_ll_add_address)
    public void onClickAddress() {
        Intent intent = new Intent();
        intent.setClass(getBaseContext(), NewsAddressListActivity.class);
        startActivityForResult(intent, REQUESTCODE);
    }

    /**
     * 订单提交
     */
    @OnClick(R.id.confirm_tv_order_commit)
    public void onClickConfirmOrderCommit() {
        if (isNoAddress == true) {
            materialDialog = new MaterialDialog(ConfirmNewCartOrderActivity.this)
                    .setMessage("确定提交订单吗？")
                    .setPositiveButton("确定", new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            initViewRequestCommit();
                            materialDialog.dismiss();
                        }
                    })
                    .setNegativeButton("取消", new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            materialDialog.dismiss();
                        }
                    });
            materialDialog.setCanceledOnTouchOutside(true);
            materialDialog.show();
        } else {
            ToastUitl.showShort("请先添加或者选择收货地址！");
        }


    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUESTCODE && resultCode == 1002) {
            isNoAddress = true;
            confirm_address_tv_name.setText(data.getStringExtra("Name"));
            confirm_address_tv_phone.setText(data.getStringExtra("Phone"));
            confirm_address_tv_details.setText(
                    data.getStringExtra("ProvinceName")
                            + data.getStringExtra("CityName")
                            + data.getStringExtra("RegionName")
                            + data.getStringExtra("DetailAddress"));
            String strId = data.getStringExtra("Id");
            addressId = Integer.valueOf(strId);
        }
    }


}
